package com.bdqn.boot.service.impl;

import com.bdqn.boot.beans.Users;
import com.bdqn.boot.mapper.UsersMapper;
import com.bdqn.boot.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.module.ResolutionException;
import java.util.List;

/**
 * @author Hasee
 * @version 1.0
 * @className UsersServiceImpl
 * @description TODD
 * @date 2025/2/26 14:11
 */
@Service
public class UsersServiceImpl implements UsersService {
    @Autowired
    private UsersMapper usersMapper;

    @Override
    public List<Users> findAll() {
        return usersMapper.findAll();
    }

    @Override
    public Users login(String userName, String pwd) {
        Users users = usersMapper.Login(userName);  // 查询用户信息
        if (users == null) {
            throw  new RuntimeException("用户名不存在"); // 如果没有找到用户，返回 null
        }
        // 检查密码是否匹配
        if (!users.getPwd().equals(pwd)) {
            throw  new RuntimeException("密码错误");
        }
        return users;
    }

}
